home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Search.aspx.cs492 < prev    next >
Text File  |  2008-05-06  |  19KB  |  457 lines

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Net;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12.  
  13. using GBPVR.Public;
  14. using GBPVRSchedule;
  15. using gbweb.classes;
  16.  
  17. namespace gbweb
  18. {
  19.     /// <summary>
  20.     /// Summary description for Search.
  21.     /// </summary>
  22.     public partial class Search : System.Web.UI.Page
  23.     {
  24.         protected System.Web.UI.HtmlControls.HtmlInputImage imageSubmit;
  25.         protected System.Web.UI.HtmlControls.HtmlTableRow trMoviesOnly;
  26.         private Settings guideParams;
  27.         private static string showSearchResults;
  28.         private static int TimelineRepeat;
  29.  
  30.         protected void Page_Load(object sender, System.EventArgs e)
  31.         {
  32.             //Code to prevent Guest users from accessing the Search page directly by URL
  33.             if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
  34.             {
  35.                 string hostAddress = string.Empty;
  36.                 string Url =
  37.                     Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
  38.                                                    Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  39.  
  40.  
  41.                 string redirectUrl = Url.ToLower().Replace("search.aspx", "guide.aspx");
  42.                 Logger.Info(" ");
  43.                 Logger.Info(" ");
  44.                 Logger.Info("Guest user trying to access the search page......");
  45.                 Logger.Info("Pulling User IP Info...");
  46.                 if (Request.UserHostAddress.Substring(0, 1) == ":")
  47.                 {
  48.                     Logger.Info("IP V6 Detected");
  49.                     hostAddress = GetIP4Address();
  50.                     Logger.Info("IP6 Address: " + Request.UserHostAddress);
  51.                     Logger.Info("IP4 Address: " + hostAddress);
  52.                     Logger.Info(" ");
  53.                 }
  54.                 else
  55.                 {
  56.                     Logger.Info("IP V4 Detected");
  57.                     hostAddress = Request.UserHostAddress;
  58.                     Logger.Info("IP4 Address: " + hostAddress);
  59.                     Logger.Info(" ");
  60.                 }
  61.                 Logger.Info("Redirecting user to the guide");
  62.                 Logger.Info(" ");
  63.                 Logger.Info(" ");
  64.                 Response.Redirect(redirectUrl, true);
  65.             }
  66.             
  67.             Session["GuideStartTime"] = null;
  68.             if (!IsPostBack)
  69.             {
  70.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  71.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  72.                 guideParams = Global.Settings;
  73.                 HttpCookie cookie = Request.Cookies["showSearchResults"];
  74.                 showSearchResults = cookie != null ? cookie.Value : "tree";
  75.  
  76.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  77.                 //options otherwise do not show them
  78.                 if (showSearchResults == "tree")
  79.                 {
  80.                     treeViewSort.Visible = true;
  81.                     //If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
  82.                     if (ExtendedEWA.Initialize())
  83.                     {
  84.                         ListItem starRating = new ListItem();
  85.                         starRating.Text = "Star Rating";
  86.                         starRating.Value = "star";
  87.                         srtOrder.Items.Add(starRating);
  88.  
  89.                         ListItem originalAirDate = new ListItem();
  90.                         originalAirDate.Text = "Original Air Date (oad)";
  91.                         originalAirDate.Value = "originalAirDate";
  92.                         srtOrder.Items.Add(originalAirDate);
  93.                     }
  94.  
  95.                     //Set the selected search order to whatever was used the last time
  96.                     cookie = Request.Cookies["SearchSortOrder"];
  97.                     srtOrder.SelectedValue = cookie != null ? cookie.Value : "title";
  98.                 }
  99.                 else
  100.                 {
  101.                     treeViewSort.Visible = false;
  102.                 }
  103.  
  104.                 Schedule scheduleHelper = Global.Schedule;
  105.                 IList listingsForPeriod;
  106.                 listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(DateTime.Now, DateTime.Now);
  107.  
  108.                 foreach (Channel channel in listingsForPeriod)
  109.                 {
  110.                     listChannels.Items.Add(new ListItem(channel.getName(), channel.channelNumber.ToString()));
  111.                 }
  112.  
  113.                 Global.FillGenreList(genreList);
  114.             }
  115.  
  116.         }
  117.  
  118.         #region Web Form Designer generated code
  119.         override protected void OnInit(EventArgs e)
  120.         {
  121.             //
  122.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  123.             //
  124.             InitializeComponent();
  125.             base.OnInit(e);
  126.         }
  127.  
  128.         /// <summary>
  129.         /// Required method for Designer support - do not modify
  130.         /// the contents of this method with the code editor.
  131.         /// </summary>
  132.         private void InitializeComponent()
  133.         {
  134.  
  135.         }
  136.         #endregion
  137.  
  138.         protected void hlSubmit_Click(object sender, EventArgs e)
  139.         {
  140.             if ((searchPhrase.Value.Length > 0) ||
  141.                 ((searchPhrase.Value.Length == 0) &&
  142.                 ((genreList.SelectedValue != null && genreList.SelectedValue != "") ||
  143.                  (startDate.PostedDate != null && startDate.PostedDate != "") ||
  144.                  (startTime.PostedTime != null && startTime.PostedTime != "") ||
  145.                  (endDate.PostedDate != null && endDate.PostedDate != "") ||
  146.                  (endTime.PostedTime != null && endTime.PostedTime != "") ||
  147.                  (textMinLength.Value != null && textMinLength.Value != "") ||
  148.                  (textMaxLength.Value != null && textMaxLength.Value != "") ||
  149.                  (listChannels.SelectedValue != null && listChannels.SelectedValue != ""))))
  150.             {
  151.                 //Store the selected sort order in the cookie for the next search
  152.                 HttpCookie cookie = new HttpCookie("SearchSortOrder", srtOrder.SelectedValue);
  153.                 cookie.Expires = DateTime.Now.AddYears(1);
  154.                 Response.Cookies.Add(cookie);
  155.  
  156.                 //Since we are using server.transfer the updated cookie is not availble to the results page.
  157.                 //We must use server.transfer to easily pass the selcted options and search text to the results page
  158.                 //for processing.
  159.                 Session["SearchResultsOption"] = srtOrder.SelectedValue;
  160.  
  161.  
  162.                 //Transfer user to Search Results page for viewing
  163.                 Server.Transfer("SearchResults.aspx");
  164.             }
  165.         }
  166.  
  167.         protected void hlReset_Click(object sender, EventArgs e)
  168.         {
  169.             //Back to search page to reset values
  170.             Response.Redirect("Search.aspx");
  171.         }
  172.  
  173.         protected void loadSearch(object sender, EventArgs e)
  174.         {
  175.             if (savedSearchList.SelectedIndex != 0)
  176.             {
  177.                 SavedSearchUtils searchUtils = new SavedSearchUtils();
  178.                 SavedSearch search = searchUtils.loadSearch(savedSearchList.SelectedValue);
  179.                 autoSearchInclude.Checked = search.isAutoShowSearch();
  180.                 autoRecordInclude.Checked = search.isAutoRecordSearch();
  181.                 checkTitle.Checked = search.getSearchTitle();
  182.                 checkDescription.Checked = search.getSearchDescription();
  183.                 checkSubTitle.Checked = search.getSearchSubTitle();
  184.                 searchPhrase.Value = search.getSearchPhrase();
  185.                 caseSensitive.Checked = search.isCaseSensitiveSearch();
  186.                 textMinLength.Value = search.getSearchLengthMin();
  187.                 textMaxLength.Value = search.getSearchLengthMax();
  188.                 if (search.getTreeViewSortOrder() != "")
  189.                 {
  190.                     srtOrder.SelectedValue = search.getTreeViewSortOrder();
  191.                 }
  192.  
  193.                 if (search.getSearchStartDate() != null && search.getSearchStartDate() != "" && search.getSearchStartDate() != "1/1/0001")
  194.                 {
  195.                     startDate.SelectedDate = searchUtils.toDate(search.getSearchStartDate());
  196.                 }
  197.                 else
  198.                 {
  199.                     startDate.Clear();
  200.                 }
  201.                 if (search.getSearchStartTime() != null && search.getSearchStartTime() != "" && (search.getSearchStartDate() != "1/1/0001" && search.getSearchStartTime() != "12:00 AM"))
  202.                 {
  203.                     startTime.SelectedTime = searchUtils.toDate(search.getSearchStartTime());
  204.                 }
  205.                 else
  206.                 {
  207.                     startTime.Clear();
  208.                 }
  209.                 if (search.getSearchEndDate() != null && search.getSearchEndDate() != "" && search.getSearchEndDate() != "1/1/0001")
  210.                 {
  211.                     endDate.SelectedDate = searchUtils.toDate(search.getSearchEndDate());
  212.                 }
  213.                 else
  214.                 {
  215.                     endDate.Clear();
  216.                 }
  217.                 if (search.getSearchEndTime() != null && search.getSearchEndTime() != "" && (search.getSearchEndDate() != "1/1/0001" && search.getSearchEndTime() != "12:00 AM"))
  218.                 {
  219.                     endTime.SelectedTime = searchUtils.toDate(search.getSearchEndTime());
  220.                 }
  221.                 else
  222.                 {
  223.                     endTime.Clear();
  224.                 }
  225.  
  226.                 genreList.SelectedIndex = -1;
  227.                 listChannels.SelectedIndex = -1;
  228.                 
  229.                 foreach (string genre in search.getSearchGenres())
  230.                 {
  231.                     try
  232.                     {
  233.                         genreList.Items.FindByValue(genre).Selected = true;
  234.                     }
  235.                     catch
  236.                     {
  237.                     }
  238.                 }
  239.  
  240.                 foreach (string channel in search.getSearchChannels())
  241.                 {
  242.                     try
  243.                     {
  244.                         listChannels.Items.FindByValue(channel).Selected = true;
  245.                     }
  246.                     catch
  247.                     {
  248.                     }
  249.                 }
  250.                 //If our saved search does not match the current search version value then we need to update it so that it has all the new default values
  251.                 guideParams = Global.Settings;
  252.                 if (search.getSearchVersion() != guideParams.CurrentSearchVersion)
  253.                 {
  254.                     updateSavedSearch_Click(null, null);
  255.                 }
  256.             }
  257.             else
  258.             {
  259.                 newSearchName.Value = "";
  260.                 searchPhrase.Value = "";
  261.                 foreach (ListItem item in genreList.Items)
  262.                 {
  263.                     item.Selected = false;
  264.                 }
  265.                 foreach (ListItem item in listChannels.Items)
  266.                 {
  267.                     item.Selected = false;
  268.                 }
  269.             }
  270.         }
  271.  
  272.         protected void deleteSavedSearch_Click(object sender, EventArgs e)
  273.         {
  274.             if (savedSearchList.SelectedIndex != 0)
  275.             {
  276.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  277.                 searchUtil.deleteSearch(savedSearchList.SelectedValue);
  278.                 savedSearchList.Items.Clear();
  279.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  280.                 savedSearchList.SelectedIndex = 0;
  281.  
  282.                 newSearchName.Value = "";
  283.                 searchPhrase.Value = "";
  284.                 foreach (ListItem item in genreList.Items)
  285.                 {
  286.                     item.Selected = false;
  287.                 }
  288.                 foreach (ListItem item in listChannels.Items)
  289.                 {
  290.                     item.Selected = false;
  291.                 }
  292.  
  293.             }
  294.         }
  295.  
  296.         protected void saveSearch_Click(object sender, EventArgs e)
  297.         {
  298.  
  299.             if (newSearchName.Value.Length > 0)
  300.             {
  301.                 SavedSearch search = new SavedSearch();
  302.                 search.setSearchName(newSearchName.Value);
  303.                 search.setautoShowSearch(autoSearchInclude.Checked);
  304.                 search.setautoRecordSearch(autoRecordInclude.Checked);
  305.                 search.setSearchTitle(checkTitle.Checked);
  306.                 search.setSearchSubTitle(checkSubTitle.Checked);
  307.                 search.setSearchDescription(checkDescription.Checked);
  308.                 search.setSearchPhrase(searchPhrase.Value);
  309.                 search.setSearchCaseSensitive(caseSensitive.Checked);
  310.                 foreach(ListItem item in genreList.Items)
  311.                 {
  312.                     if (item.Selected)
  313.                     {
  314.                         search.addSearchGenres(item.Value);
  315.                     }
  316.                 }
  317.                 if (treeViewSort.Visible)
  318.                 {
  319.                     search.setTreeviewSortOrder(srtOrder.SelectedValue);
  320.                 }
  321.                 search.setSearchLengthMin(textMinLength.Value);
  322.                 search.setSearchLengthMax(textMaxLength.Value);
  323.                 foreach (ListItem item in listChannels.Items)
  324.                 {
  325.                     if (item.Selected)
  326.                     {
  327.                         search.addSearchChannels(item.Value);
  328.                     }
  329.                 }
  330.  
  331.                 if (searchPhrase.Value.Length == 0 && genreList.SelectedIndex == -1 && listChannels.SelectedIndex == -1 &&
  332.                     textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
  333.                 {
  334.                     search.setSearchPhrase(newSearchName.Value);
  335.                     searchPhrase.Value = newSearchName.Value;
  336.                 }
  337.  
  338.                 if (startDate.PostedDate != "")
  339.                 {
  340.                     search.setSearchStartDate(startDate.PostedDate);
  341.                 }
  342.                 else
  343.                 {
  344.                     search.setSearchStartDate(null);
  345.                 }
  346.                 search.setSearchStartTime(startTime.PostedTime);
  347.  
  348.                 if (endDate.PostedDate != "")
  349.                 {
  350.                     search.setSearchEndDate(endDate.PostedDate);
  351.                 }
  352.                 else
  353.                 {
  354.                     search.setSearchEndDate(null);
  355.                 }
  356.                 search.setSearchEndTime(endTime.PostedTime);
  357.  
  358.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  359.                 searchUtil.deleteSearch(newSearchName.Value);
  360.                 searchUtil.writeSearch(search);
  361.                 savedSearchList.Items.Clear();
  362.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  363.                 savedSearchList.SelectedValue = newSearchName.Value;
  364.                 newSearchName.Value = string.Empty;
  365.             }
  366.         }
  367.  
  368.         protected void updateSavedSearch_Click(object sender, EventArgs e)
  369.         {
  370.             SavedSearch search = new SavedSearch();
  371.             guideParams = Global.Settings;
  372.             search.setSearchName(savedSearchList.SelectedValue);
  373.             search.setSearchVersion(guideParams.CurrentSearchVersion);
  374.             search.setautoShowSearch(autoSearchInclude.Checked);
  375.             search.setautoRecordSearch(autoRecordInclude.Checked);
  376.             search.setSearchTitle(checkTitle.Checked);
  377.             search.setSearchSubTitle(checkSubTitle.Checked);
  378.             search.setSearchDescription(checkDescription.Checked);
  379.             search.setSearchPhrase(searchPhrase.Value);
  380.             search.setSearchCaseSensitive(caseSensitive.Checked);
  381.             foreach (ListItem item in genreList.Items)
  382.             {
  383.                 if (item.Selected)
  384.                 {
  385.                     search.addSearchGenres(item.Value);
  386.                 }
  387.             }
  388.             if (treeViewSort.Visible)
  389.             {
  390.                 search.setTreeviewSortOrder(srtOrder.SelectedValue);
  391.             }
  392.             search.setSearchLengthMin(textMinLength.Value);
  393.             search.setSearchLengthMax(textMaxLength.Value);
  394.             foreach (ListItem item in listChannels.Items)
  395.             {
  396.                 if (item.Selected)
  397.                 {
  398.                     search.addSearchChannels(item.Value);
  399.                 }
  400.             }
  401.  
  402.             if (searchPhrase.Value.Length == 0 && genreList.Items.Count == 0 && listChannels.Items.Count == 0 &&
  403.                 textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
  404.             {
  405.                 search.setSearchPhrase(newSearchName.Value);
  406.             }
  407.  
  408.             if (startDate.PostedDate != "")
  409.             {
  410.                 search.setSearchStartDate(startDate.PostedDate);
  411.             }
  412.             else
  413.             {
  414.                 search.setSearchStartDate(null);
  415.             }
  416.             search.setSearchStartTime(startTime.PostedTime);
  417.  
  418.             if (endDate.PostedDate != "")
  419.             {
  420.                 search.setSearchEndDate(endDate.PostedDate);
  421.             }
  422.             else
  423.             {
  424.                 search.setSearchEndDate(null);
  425.             }
  426.             search.setSearchEndTime(endTime.PostedTime);
  427.  
  428.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  429.             searchUtil.deleteSearch(savedSearchList.SelectedValue);
  430.             searchUtil.writeSearch(search);
  431.          }
  432.         protected void savedSearchFilter_SelectedIndexChanged(object sender, EventArgs e)
  433.         {
  434.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  435.             savedSearchList.Items.Clear();
  436.             searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  437.         }
  438.  
  439.  
  440.         public string GetIP4Address()
  441.         {
  442.             string strIP4Address = String.Empty;
  443.  
  444.             foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
  445.             {
  446.                 if (objIP.AddressFamily.ToString() == "InterNetwork")
  447.                 {
  448.                     strIP4Address = objIP.ToString();
  449.                     break;
  450.                 }
  451.             }
  452.             return strIP4Address;
  453.         }
  454.  
  455. }
  456. }
  457.